package com.zyg.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyg.shop.dao.BrandDao;
import com.zyg.shop.entity.BrandEntity;
import com.zyg.shop.service.BrandService;
import com.zyg.common.utils.PageUtils;
import com.zyg.common.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //1. 构造查询包装器
        QueryWrapper<BrandEntity> wrapper = new QueryWrapper<BrandEntity>();
        //2. 得到参数key
        String key = (String) params.get("key");
        System.out.println("key = " + key);

        //3. 判断是否有值，添加各种查询条件
        if(StringUtils.isNotBlank(key)){
            wrapper.like("name", key );
            wrapper.or().like("first_char",key );
            wrapper.or().like("id",key);
        }
        //4. 开始条件带分页查询
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}